home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17026 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: ix.netcom.com!news
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Help! Macro replacement......
  5. Date: Fri, 12 Apr 1996 18:42:36 GMT
  6. Organization: Netcom
  7. Message-ID: <316e9feb.158491368@nntp.ix.netcom.com>
  8. References: <4kega2$1tk@hptemp1.cc.umr.edu>
  9. NNTP-Posting-Host: ix-dc11-06.ix.netcom.com
  10. X-NETCOM-Date: Fri Apr 12  1:43:10 PM CDT 1996
  11. X-Newsreader: Forte Agent .99d/32.182
  12.  
  13. jlu@cs.umr.edu (Eric Jui-Lin Lu) wrote:
  14.  
  15. > Hi *,
  16. > I wrote an ugly macro definition which, when I compiled, surprised
  17. > me. The macro is defined as
  18. >    #define ABS(X) ((X <= 0) ? -X : X)
  19. > And I called the macro by using
  20. >    int y = ABS(-6+4);
  21. > I expected y would be 10. However, Solaris CC and Turbo C++ version 3.0
  22. > for DOS returned compilation error. And IRIX CC and g++ version 2.6.3 
  23. > and 2.7.0 returned 10.
  24. > The problem is clear that one replacement gives
  25. >    int y = --6+4;    // compilation error
  26. > And the other gives
  27. >    int y = - -6+4; // y = 10
  28. > I tried to find out the answer from Chap 16 of ANSI C++ standard 
  29. > draft but cannot figure out which one is correct. Will someone 
  30. > please EMAIL me which one conforms to ANSI C++? If interested, I 
  31. > can post the summary. Thanks!
  32.  
  33. IRIX and g++ are correct.  The input is parsed into preprocessor
  34. tokens before preprocessor directives are executed (draft 2.1).
  35. #define uses these preprocessing tokens (draft 16.3).  It seems that
  36. the other compilers are doing string substitution before parsing into
  37. preprocessor tokens.
  38.  
  39. Michael M Rubenstein
  40.